import type { TooltipProps } from 'antd';
import type { YmColProps } from 'ym-design';
import type { ReportMetaChange } from '../Context/NoStyleItemContext';
import type { FieldProps, Meta } from './FieldEntityType';
import type { FormInstance, FormLabelAlign } from './index';

export type WrapperTooltipProps = TooltipProps & {
  icon?: React.ReactElement;
};
export type ValidateStatus =
  | 'success'
  | 'warning'
  | 'error'
  | 'validating'
  | '';

export type LabelTooltipType = WrapperTooltipProps | React.ReactNode;

export interface FormItemLabelProps {
  colon?: boolean;
  htmlFor?: string;
  label?: React.ReactNode;
  labelAlign?: FormLabelAlign;
  labelCol?: YmColProps;
  tooltip?: LabelTooltipType;
  required?: boolean;
}

export interface FormItemInputProps {
  wrapperCol?: YmColProps;
  extra?: React.ReactNode;
  status?: ValidateStatus;
  help?: React.ReactNode;
  fieldId?: string;
  children: React.ReactNode;
  errors: React.ReactNode[];
  warnings: React.ReactNode[];
  marginBottom?: number | null;
  onErrorVisibleChanged?: (visible: boolean) => void;
}

export interface FormItemProps<Values = any>
  extends FormItemLabelProps,
    Omit<FieldProps<Values>, 'children'> {
  help?: React.ReactNode;
  wrapperCol?: YmColProps;
  extra?: React.ReactNode;
  noStyle?: boolean;
  style?: React.CSSProperties;
  className?: string;
  id?: string;
  hasFeedback?: boolean;
  validateStatus?: ValidateStatus;
  required?: boolean;
  hidden?: boolean;
  children:
    | React.ReactNode
    | ((formInstance?: FormInstance<Values>) => React.ReactNode);
}

export interface ItemHolderProps extends Omit<FormItemProps, 'children'> {
  errors: React.ReactNode[];
  warnings: React.ReactNode[];
  meta: Meta;
  children?: React.ReactNode;
  fieldId?: string;
  onSubItemMetaChange: ReportMetaChange;
}
export interface ErrorListProps {
  fieldId?: string;
  help?: React.ReactNode;
  helpStatus?: ValidateStatus;
  errors?: React.ReactNode[];
  warnings?: React.ReactNode[];
  className?: string;
  onVisibleChanged?: (visible: boolean) => void;
}
